const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const PaymentOrder = sequelize.define('PaymentOrder', {
    id: {
        type: DataTypes.UUID,
        primaryKey: true,
        defaultValue: DataTypes.UUIDV4
    },
    user_uuid: {
        type: DataTypes.UUID,
        allowNull: false,
        comment: '用户UUID'
    },
    email: {
        type: DataTypes.STRING,
        allowNull: true
    },
    stripe_price_id: {
        type: DataTypes.STRING,
        allowNull: false,
        comment: 'Stripe Price ID'
    },
    product_name: {
        type: DataTypes.STRING,
        allowNull: true,
        comment: '产品名称'
    },
    type: {
        type: DataTypes.ENUM('disposable', 'subscription'),
        allowNull: true,
        comment: '订单类型：disposable=一次性，subscription=订阅'
    },
    stripe_payment_intent_id: {
        type: DataTypes.STRING,
        allowNull: true
    },
    stripe_session_id: {
        type: DataTypes.STRING,
        allowNull: true
    },
    stripe_subscription_id: {
        type: DataTypes.STRING,
        allowNull: true
    },
    amount: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '金额（分）'
    },
    currency: {
        type: DataTypes.STRING,
        allowNull: false,
        defaultValue: 'hkd'
    },
    status: {
        type: DataTypes.ENUM('pending', 'succeeded', 'failed', 'cancelled'),
        allowNull: false,
        defaultValue: 'pending'
    },
    payment_method: {
        type: DataTypes.ENUM('checkout', 'elements', 'subscription_renewal'),
        allowNull: false
    }
}, {
    tableName: 'payment_orders',
    comment: '支付订单表'
});

module.exports = PaymentOrder; 